package com.haizhi.crm.biz.task.message.handler;

import com.haizhi.crm.common.log.GLog;
import com.haizhi.crm.common.log.LogFactory;

/**
 * Created by wangshan on 2018/5/29.
 */
public abstract class AbstractHandler<T> {

    private static final GLog LOG = LogFactory.getLogger(AbstractHandler.class);

    private AbstractHandler nextHandler = null;

    public final MsgResponse processData(T data) {
        if (data == null) {
            return MsgResponse.error("data is null" );
        }
        MsgResponse response = this.process(data);
        if (!response.isSucess()) {
            LOG.info(response.getMessage());
            return response;
        }
        if (this.nextHandler != null) {
            this.nextHandler.processData(data);
        }
        return MsgResponse.success();
    }


    public AbstractHandler setNextHandler(AbstractHandler abstractHandler) {
        this.nextHandler = abstractHandler;
        return this;
    }

    protected abstract MsgResponse process(T data);

}
